package com.example.blog.model;

import lombok.Data;

import javax.management.openmbean.TabularData;

/**
 * ClassName: Result
 * Package: IntelliJ IDEA
 * Description:
 *
 * @Author 谷京京
 * @Create 2024/3/26 10:14
 * @Version 1.0
 */
@Data
public class Result<T> {
    private int code;//200成功, -1失败
    private String errorMeg;
    private T data;

    public static <T>Result<T> success(T data) {
        Result result = new Result();
        result.setCode(Constants.RESULT_SUCCESS);
        result.setData(data);
        result.setErrorMeg("");
        return result;
    }
    public static <T>Result<T> fail(String errorMeg) {
        Result result = new Result();
        result.setCode(Constants.RESLUT_ERROR);
        result.setErrorMeg(errorMeg);
        return result;
    }
    public static <T>Result<T> fail(String errorMeg, T data) {
        Result result = new Result();
        result.setCode(Constants.RESLUT_ERROR);
        result.setErrorMeg(errorMeg);
        result.setData(data);
        return result;
    }
}
